package com.itheima.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;

public class SqlSessionUtils {
    private static SqlSessionFactory sessionFactory;

    static {
        try {
            InputStream is = Resources.getResourceAsStream("MyBatisConfig.xml");
            sessionFactory = new SqlSessionFactoryBuilder().build(is);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //提供一个获取sqlsession连接对象
    public static SqlSession getSqlsession() {
        return sessionFactory.openSession();
    }
}
